{% extends 'base.html' %}
{% load static %}

{% block title %}管理员仪表板 - 维修管理系统{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <h1 class="mb-4">管理员仪表板</h1>
            <p class="text-muted">欢迎回来，{{ user.get_full_name|default:user.username }}！</p>
        </div>
    </div>

    <!-- 系统统计 -->
    <div class="row mb-4">
        <div class="col-md-6 col-lg-3 mb-3">
            <div class="card bg-primary text-white">
                <div class="card-body">
                    <h5 class="card-title">用户总数</h5>
                    <h2 class="card-text">{{ stats.users_total }}</h2>
                </div>
            </div>
        </div>
        <div class="col-md-6 col-lg-3 mb-3">
            <div class="card bg-info text-white">
                <div class="card-body">
                    <h5 class="card-title">工单总数</h5>
                    <h2 class="card-text">{{ stats.tickets_total }}</h2>
                </div>
            </div>
        </div>
        <div class="col-md-6 col-lg-3 mb-3">
            <div class="card bg-success text-white">
                <div class="card-body">
                    <h5 class="card-title">设备总数</h5>
                    <h2 class="card-text">{{ stats.assets_total }}</h2>
                </div>
            </div>
        </div>
        <div class="col-md-6 col-lg-3 mb-3">
            <div class="card bg-warning text-dark">
                <div class="card-body">
                    <h5 class="card-title">今日工单</h5>
                    <h2 class="card-text">{{ stats.tickets_today }}</h2>
                </div>
            </div>
        </div>
    </div>

    <!-- 管理操作 -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">管理操作</h5>
                </div>
                <div class="card-body">
                    <div class="d-grid gap-2 d-md-flex">
                        <a href="{% url 'users:user_list' %}" class="btn btn-primary me-md-2">
                            <i class="bi bi-people"></i> 用户管理
                        </a>
                        <a href="{% url 'assets:asset_manage' %}" class="btn btn-outline-primary me-md-2">
                            <i class="bi bi-pc-display"></i> 设备管理
                        </a>
                        <a href="{% url 'tickets:ticket_list_all' %}" class="btn btn-outline-primary me-md-2">
                            <i class="bi bi-list-check"></i> 工单管理
                        </a>
                        <a href="{% url 'reports' %}" class="btn btn-outline-secondary">
                            <i class="bi bi-bar-chart"></i> 报表统计
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 待处理工单区域 -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">待处理工单</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <!-- 待登记签收 -->
                        <div class="col-md-6 col-lg-3 mb-3">
                            <div class="card bg-primary text-white">
                                <div class="card-body text-center">
                                    <h5 class="card-title">待登记签收</h5>
                                    <h2 class="card-text">{{ applied_count }}</h2>
                                    <small>applied状态</small>
                                </div>
                            </div>
                        </div>
                        <!-- 待分配技术人员 -->
                        <div class="col-md-6 col-lg-3 mb-3">
                            <div class="card bg-info text-white">
                                <div class="card-body text-center">
                                    <h5 class="card-title">待分配</h5>
                                    <h2 class="card-text">{{ registered_count }}</h2>
                                    <small>registered状态</small>
                                </div>
                            </div>
                        </div>
                        <!-- 待检测 -->
                        <div class="col-md-6 col-lg-3 mb-3">
                            <div class="card bg-warning text-dark">
                                <div class="card-body text-center">
                                    <h5 class="card-title">待检测</h5>
                                    <h2 class="card-text">{{ assigned_count }}</h2>
                                    <small>assigned状态</small>
                                </div>
                            </div>
                        </div>
                        <!-- 待维修 -->
                        <div class="col-md-6 col-lg-3 mb-3">
                            <div class="card bg-warning text-dark">
                                <div class="card-body text-center">
                                    <h5 class="card-title">待维修</h5>
                                    <h2 class="card-text">{{ testing_count }}</h2>
                                    <small>testing状态</small>
                                </div>
                            </div>
                        </div>
                        <!-- 待质检 -->
                        <div class="col-md-6 col-lg-3 mb-3">
                            <div class="card bg-info text-white">
                                <div class="card-body text-center">
                                    <h5 class="card-title">待质检</h5>
                                    <h2 class="card-text">{{ repairing_count }}</h2>
                                    <small>repairing状态</small>
                                </div>
                            </div>
                        </div>
                        <!-- 待完成 -->
                        <div class="col-md-6 col-lg-3 mb-3">
                            <div class="card bg-success text-white">
                                <div class="card-body text-center">
                                    <h5 class="card-title">待完成</h5>
                                    <h2 class="card-text">{{ quality_check_count }}</h2>
                                    <small>quality_check状态</small>
                                </div>
                            </div>
                        </div>
                        <!-- 待返还 -->
                        <div class="col-md-6 col-lg-3 mb-3">
                            <div class="card bg-success text-white">
                                <div class="card-body text-center">
                                    <h5 class="card-title">待返还</h5>
                                    <h2 class="card-text">{{ completed_count }}</h2>
                                    <small>completed状态</small>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 系统状态和通知 -->
    <div class="row">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">系统状态</h5>
                </div>
                <div class="card-body">
                    <div class="alert alert-success">
                        <h6 class="alert-heading">系统运行正常</h6>
                        <p class="mb-0 small">所有服务正常运行，无异常情况。</p>
                    </div>
                    <div class="alert alert-info">
                        <h6 class="alert-heading">数据统计</h6>
                        <p class="mb-0 small">今日新增 {{ stats.tickets_today }} 个工单。</p>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-6">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="card-title mb-0">系统通知</h5>
                    <a href="{% url 'notifications:notification_list' %}" class="btn btn-sm btn-outline-primary">
                        <i class="bi bi-gear"></i> 管理
                    </a>
                </div>
                <div class="card-body">
                    {% if notifications %}
                        {% for notification in notifications %}
                        <div class="alert alert-{{ notification.get_priority_class }} mb-2">
                            <div class="d-flex justify-content-between align-items-start">
                                <div>
                                    <h6 class="alert-heading mb-1">{{ notification.title }}</h6>
                                    <p class="mb-0 small">{{ notification.content|truncatewords:15 }}</p>
                                </div>
                                <small class="text-muted">{{ notification.created_at|date:"m-d H:i" }}</small>
                            </div>
                        </div>
                        {% endfor %}
                    {% else %}
                        <div class="text-center text-muted py-3">
                            <i class="bi bi-bell" style="font-size: 2rem;"></i>
                            <p class="mt-2 mb-0">暂无通知</p>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
